package com.aso114.project.mvp.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aso114.project.R;
import com.aso114.project.adapter.SelectedTopicAdapter;
import com.aso114.project.base.BaseSimpleActivity;
import com.aso114.project.bean.JingPinBean;
import com.aso114.project.mvp.model.CallBack;
import com.aso114.project.mvp.model.CommentModel;
import com.aso114.project.util.Helper;
import com.aso114.project.util.SpaceItemDecoration;
import com.aso114.project.util.SystemBarHelper;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 精选押题
 */
public class SelectedTopicActivity extends BaseSimpleActivity {
    @BindView(R.id.layout_title_bar_back_iv)
    ImageView layoutTitleBarBackIv;
    @BindView(R.id.layout_title_bar_title_tv)
    TextView layoutTitleBarTitleTv;
    @BindView(R.id.layout_title_bar_right_iv)
    ImageView layoutTitleBarRightIv;
    @BindView(R.id.layout_title_bar_right_tv)
    TextView layoutTitleBarRightTv;
    @BindView(R.id.title_top_ly)
    RelativeLayout titleTopLy;
    @BindView(R.id.topic_listView)
    RecyclerView topicListView;

    SelectedTopicAdapter selectedTopicAdapter;

    @Override
    protected int getResouseId() {
        return R.layout.activity_selected_topic;
    }

    @Override
    protected void initView() {
        SystemBarHelper.immersiveStatusBar(this);
        SystemBarHelper.setHeightAndPadding(this, titleTopLy);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            SystemBarHelper.immersiveStatusBar(this, 0);
            SystemBarHelper.setStatusBarDarkMode(this);
        }
        layoutTitleBarTitleTv.setText("精选押题");
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        //设置布局管理器
        topicListView.setLayoutManager(layoutManager);
        selectedTopicAdapter = new SelectedTopicAdapter(this);
        topicListView.setAdapter(selectedTopicAdapter);
        getData();
    }

    private void getData() {
        CommentModel.getInstant().getJingPin(new CallBack() {
            @Override
            public void onSuccess(Object o, boolean isSuccess, String msg) {
                Helper.gotoLogin(isSuccess);//token失效去重新登陆
                ArrayList<JingPinBean> bean = (ArrayList<JingPinBean>)o;
                if (bean==null||bean.isEmpty()){
                    return;
                }
                selectedTopicAdapter.setData(bean);
                selectedTopicAdapter.notifyDataSetChanged();
            }

            @Override
            public void onFailure(String fail) {

            }
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void getBroadcast(Context context, Intent intent) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick(R.id.layout_title_bar_back_iv)
    public void onViewClicked() {
        finish();
    }
}
